package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/admin/order")
@RestController(value = "admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询订单详情
     */
    @GetMapping("/details/{id}")
    Result getDetails(@PathVariable Long id){
        log.info("要查询的订单id:{}",id);
        OrderVO orderDetail = orderService.getOrderDetail(id);
        return Result.success(orderDetail);
    }

    /**
     * 订单搜索
     */
    @GetMapping("/conditionSearch")
    Result getConditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单搜素请求参数:{}",ordersPageQueryDTO);
        PageResult pageResult =orderService.getConditionSearch(ordersPageQueryDTO);
        log.info("pageResult:{}",pageResult);
        return Result.success(pageResult);
    }

    /**
     * 各个状态的订单数量
     */
    @GetMapping("/statistics")
    Result getStatistics(){
        OrderStatisticsVO orderStatisticsVO= orderService.getStatistics();
        log.info("orderStatisticsVO:{}",orderStatisticsVO);
        return Result.success(orderStatisticsVO);
    }

    /**
     * 商家接单
     */
    @PutMapping("/confirm")
    Result confirmOrders(@RequestBody Orders orders){
        log.info("要接的订单信息为:{}",orders);
        orderService.confirmOrders(orders);
        return Result.success();
    }

    /**
     *商家拒单
     */
    @PutMapping("/rejection")
    Result rejectionOrders(@RequestBody Orders orders){
        log.info("要拒绝的订单信息为:{}",orders);
        orderService.rejectionOrders(orders);
        return Result.success();
    }

    /**
     * 取消订单
     */
    @PutMapping("/cancel")
    Result shopCancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("商家取消订单:{}",ordersCancelDTO);
        orderService.shopCancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 派送订单
     */
    @PutMapping("/delivery/{id}")
    Result delivery(@PathVariable Long id){
        log.info("派送订单的订单号为:{}",id);
        orderService.delivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     */
    @PutMapping("/complete/{id}")
    Result complete(@PathVariable Long id){
        log.info("完成的订单号为:{}",id);
        orderService.complete(id);
        return Result.success();
    }



}
